using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Security.Cryptography;
using PlugNT.Safe;
using PlugNT.Database.Common;
using PlugNT.Database.Common.Simple;
using PlugNT.Custom;
using PlugNT.Cms.Model;

namespace PlugNT.Cms.DAL
{
    public class Sys
    {

        private static string currTableName = WebConfig.TablePrefix + "sys";



        private SysInfo GetSysInfo(DataRow dr)
        {
            SysInfo model = new SysInfo();

            model.id = (int)dr["id"];
            model.articleupdated = (bool)dr["articleupdated"];
            model.commentfilter = dr["commentfilter"].ToString();
            model.usersadminhtml = dr["usersadminhtml"].ToString();

            return model;
        }





        public SysInfo GetSysInfo()
        {
            SysInfo model = null;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 * from " + currTableName);
            DataTable dt = DbHelper.TabQuery(strSql.ToString());
            if (dt.Rows.Count > 0)
            {
                model = GetSysInfo(dt.Rows[0]);
            }
            return model;
        }











        public bool Update(SysInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + currTableName + " set ");
            strSql.Append("articleupdated=" + (model.articleupdated ? "1" : "0") + ",");
            strSql.Append("commentfilter='" + StringHelper.SqlFilter(model.commentfilter) + "',");
            strSql.Append("usersadminhtml='" + StringHelper.SqlFilter(model.usersadminhtml) + "' ");
            strSql.Append(" where id=" + model.id.ToString());

            return (DbHelper.ExecuteSql(strSql.ToString()) > 0) ? true : false;
        }

        public bool UpdateArticleupdated(int id,bool articleupdated)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + currTableName + " set ");
            strSql.Append("articleupdated=" + (articleupdated ? "1" : "0")+" where id="+id.ToString());

            return (DbHelper.ExecuteSql(strSql.ToString()) > 0) ? true : false;
        }

        public bool UpdateCommentfilter(int id, string commentfilter)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + currTableName + " set ");
            strSql.Append("commentfilter='" + StringHelper.SqlFilter(commentfilter) + "' where id=" + id.ToString());

            return (DbHelper.ExecuteSql(strSql.ToString()) > 0) ? true : false;
        }

        public bool UpdateUsersadminhtml(int id, string usersadminhtml)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + currTableName + " set ");
            strSql.Append("usersadminhtml='" + StringHelper.SqlFilter(usersadminhtml) + "' where id=" + id.ToString());

            return (DbHelper.ExecuteSql(strSql.ToString()) > 0) ? true : false;
        }







        public string Help()
        {
            return @"mailto:354990393@qq.com";
        }


    }
}
